package com.whq.thrift.api.web.admin.db.baseconf;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

public interface ModuleInstanceMapper {
	
	@Select("select * from t_module_instance where instance_id=#{instanceId}")
	@Results(
		value = {
			@Result(property="instanceId", column="instance_id"),
			@Result(property="moduleId", column="module_id"),
			@Result(property="ip", column="ip"),
			@Result(property="port", column="port"),
			@Result(property="status", column="status"),
			@Result(property="createTime", column="create_time"),
			@Result(property="updateTime", column="update_time")
		}
	)
	public ModuleInstance getRecordByKey(@Param("instanceId") String instanceId);

	@Insert("INSERT INTO t_module_instance (module_id, ip, port, status, create_time, update_time) "
			+ " VALUES(#{moduleId}, #{ip}, #{port}, #{status}, #{createTime}, #{updateTime})")
	@Options(useGeneratedKeys = true, keyProperty = "instanceId")
	public void addRecord(ModuleInstance moduleInstance);
	
	@SelectProvider(type = ModuleInstanceSqlProvider.class, method = "getSelectRecordsSql")
	@Results(
			value = {
				@Result(property="instanceId", column="instance_id"),
				@Result(property="moduleId", column="module_id"),
				@Result(property="ip", column="ip"),
				@Result(property="port", column="port"),
				@Result(property="status", column="status"),
				@Result(property="createTime", column="create_time"),
				@Result(property="updateTime", column="update_time")
			}
		)
    public List<ModuleInstance> findRecordsByMap(Map<String, Object> whereParams);
	
	@SelectProvider(type = ModuleInstanceSqlProvider.class, method = "getSelectCountSql")
    public int findRecordsCount(Map<String, Object> whereParams);
	
	@UpdateProvider(type = ModuleInstanceSqlProvider.class, method = "getUpdateSql")
	public void updRecord(ModuleInstance moduleInstance);
	
	@Delete("delete from t_module_instance where instance_id=#{instanceId}")
	public void delRecord(@Param("instanceId") String instanceId);
}
